package com.netsdk.controller;

import com.netsdk.demo.module.GateModule;
import com.netsdk.entity.Dhsdk;
import com.netsdk.lib.ToolKits;
import com.netsdk.mapper.DhsdkMapper;
import com.sun.jna.Memory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/person/")
public class PersonController {

    @Autowired
    private DhsdkMapper dhsdkMapper;

    @GetMapping("addPersonPic")
    public String addPersonPic(String path) {
        try {
            //读取图片缓存
            Memory memory = ToolKits.readPictureFile(path);
            GateModule.addFaceInfo("1", memory);

            return "添加成功";
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }


    @GetMapping("updatePersonPic")
    public String updatePersonPic(String path) {
        try {
            //读取图片缓存
            Memory memory = ToolKits.readPictureFile("D:\\img\\lian.jpg");
            boolean b = GateModule.modifyFaceInfo("1", memory);
            if (b) {
                return "修改成功";
            }
            return "修改失败";
        } catch (IOException e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }

    @GetMapping("aaa")
    public String aaa() {
        Dhsdk dhsdk = new Dhsdk("000009", "成功",
                "123", "12", "1");
        int count = dhsdkMapper.insert(dhsdk);
        System.out.println(count);
        return "添加陈工！" + count;
    }
}
